package cn.cs.service.impl;

import cn.cs.client.RestAppOrderClient;
import cn.cs.client.UserRepairApplyClient;
import cn.cs.common.Constants;
import cn.cs.common.EmptyUtils;
import cn.cs.common.Page;
import cn.cs.pojo.AppOrder;
import cn.cs.pojo.UserRepairApply;
import cn.cs.service.UserRepairApplyService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class UserRepairApplyServiceImpl implements UserRepairApplyService {

    @Resource
    private UserRepairApplyClient userRepairApplyClient;

    @Resource
    private RestAppOrderClient appOrderClient;

    public UserRepairApply getUserRepairApplyById(String id) throws Exception {
        return userRepairApplyClient.getUserRepairApplyById(id);
    }

    public List<UserRepairApply> getUserRepairApplyListByMap(Map<String, Object> param) throws Exception {
        return userRepairApplyClient.getUserRepairApplyListByMap(param);
    }

    public Integer getUserRepairApplyCountByMap(Map<String, Object> param) throws Exception {
        return userRepairApplyClient.getUserRepairApplyCountByMap(param);
    }

    public Integer addUserRepairApply(UserRepairApply userRepairApply) throws Exception {
        return userRepairApplyClient.insertUserRepairApply(userRepairApply);
    }

    public Integer modifyUserRepairApply(UserRepairApply userRepairApply) throws Exception {
        return userRepairApplyClient.updateUserRepairApply(userRepairApply);
    }

    public Integer deleteUserRepairApplyById(String id) throws Exception {
        return userRepairApplyClient.deleteUserRepairApplyById(id);
    }

    public Page<UserRepairApply> queryUserRepairApplyPageByMap(Map<String, Object> param, Integer pageNo, Integer pageSize) throws Exception {
        Integer total = userRepairApplyClient.getUserRepairApplyCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<UserRepairApply> userRepairApplyList = userRepairApplyClient.getUserRepairApplyListByMap(param);
        page.setRows(userRepairApplyList);
        return page;
    }

    public Integer userRepairApplyOrder(AppOrder appOrder)throws Exception{
        return appOrderClient.userRepairApplyOrder(appOrder);
    }

    public List<Map<String, Object>> getRepairUserByAreaIdOnlyWork(String area)throws Exception{
        return userRepairApplyClient.getRepairUserByAreaIdOnlyWork(area);
    }

}
